package org.wmq.shopmanager.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.wmq.commonutil.result.Result;
import org.wmq.shopmanager.service.CategoryBrandService;
import org.wmq.shopmodel.DTO.product.CategoryBrandQueryDTO;
import org.wmq.shopmodel.Entity.product.Brand;
import org.wmq.shopmodel.Entity.product.CategoryBrand;

import java.util.List;

@RestController
@RequestMapping("/admin/product/category-brand")
@RequiredArgsConstructor
public class CategoryBrandController {
    private final CategoryBrandService categoryBrandService;

    @GetMapping("page")
    public Result<IPage<CategoryBrand>> getCategoryBrandPageItem(@ModelAttribute CategoryBrandQueryDTO categoryBrandQueryDTO){
        return Result.success(this.categoryBrandService.getPageItem(categoryBrandQueryDTO));
    }
    @PostMapping
    public Result<Void> saveCategoryBrand(@RequestBody CategoryBrand categoryBrand){
        this.categoryBrandService.save(categoryBrand);
        return Result.success();
    }
    @GetMapping("getBrandListByCategoryId/{categoryId}")
    public Result<List<Brand>> getBrandListByCategoryId(@PathVariable Long categoryId){
        return Result.success(this.categoryBrandService.getBrandListByCategoryId(categoryId));
    }
}
